﻿/// <reference path="../../Scripts/commen_js/MJ_JSComment.js" />
/// <reference path="../../Scripts/commen_js/jquery-2.0.2.min.js" />
var AboutObject = {
    BindBata: function () {
        var productuid = GetQueryString("productid");
        poststr = "{\"type\":\"aboutobject\",\"htmldata\":\""+productuid+"\"}";
        this.postajaxs(poststr, this.showdata);
    },
    showdata: function (data) {
        if (data.result == "ok") {
            var tabledata = data.table;
            var imgbase = document.getElementById("tablebody");
            $("#tablebody").empty();
            if (tabledata.length != 0) {
                for (i = 0; i < tabledata.length ; i++) {
                        var tr = document.createElement("tr");
                        var td1 = document.createElement("td");
                        var td2 = document.createElement("td");
                        var img = document.createElement("img");
                        img.src = "../" + tabledata[i].childimg;
                        var div = document.createElement("div");
                        div.innerHTML = $.trim(tabledata[i].product_name) + $.trim(tabledata[i].product_type);
                        var checkbox = document.createElement("input");
                        checkbox.type = "checkbox";
                        checkbox.name = "allname";
                        checkbox.style.marginRight = "10px";
                        checkbox.value = $.trim(tabledata[i].id);
                        var div1 = document.createElement("div");
                        div1.appendChild(checkbox);
                        var span = document.createElement("span");
                        span.innerHTML = "价格：" + $.trim(tabledata[i].price);
                        div1.appendChild(span);
                        var addone = i + 1;
                        if (addone < tabledata.length) {
                            var img1 = document.createElement("img");
                            img1.src = "../" + tabledata[addone].childimg;
                            i++;
                            var div2 = document.createElement("div");
                            div2.innerHTML =$.trim(tabledata[addone].product_name) +$.trim(tabledata[addone].product_type);
                            var div3 = document.createElement("div");
                            var checkbox1 = document.createElement("input");
                            checkbox1.type = "checkbox";
                            checkbox1.name = "allname";
                            checkbox1.style.marginRight = "10px";
                            checkbox1.value = $.trim(tabledata[addone].id);
                            var span1 = document.createElement("span");
                            span1.innerHTML = "价格：" + $.trim(tabledata[addone].price);
                            div3.appendChild(checkbox1);
                            div3.appendChild(span1);
                            td1.appendChild(img);
                            td1.appendChild(div);
                            td1.appendChild(div1);
                            td2.appendChild(img1);
                            td2.appendChild(div2);
                            td2.appendChild(div3);
                        }
                        else {
                            i++;
                            td1.appendChild(img);
                            td1.appendChild(div);
                            td1.appendChild(div1);
                        }
                        tr.appendChild(td1);
                        tr.appendChild(td2);
                        imgbase.appendChild(tr);
                        $("#detale").text(tabledata[0].product_detale);
                    }
            }
        }
        else {
            layer_alert_error(data.msg);
        }
    },
    changecount: function (id) {
        var countnow = $.trim($("#nowcount").text());
        if (id == "reduce") {
            var count = countnow == 1 ? 1 : countnow -1 ;
            $("#nowcount").text(count);
        }
        else if (id == "add") {
            var count = parseInt(countnow) +1;
            $("#nowcount").text(count);
        }
    },
    buyproduct: function () {
        var productuid = GetQueryString("productid");
        var str = document.getElementsByName("allname");
        var objarray = str.length;
        var chestr = "";
        for (i = 0; i < objarray; i++) {
            if (str[i].checked == true) {
                if (chestr == "") {
                    chestr += str[i].value.replace("radio", "");
                }
                else {
                    chestr += "|" + str[i].value.replace("radio", "");
                }
            }
        }
        if (chestr == "") {
            alert("请选择商品");
            return;
        }
        location.href = "buy.aspx?" + "productid=" + chestr + "&resoretype=Product&r=" + Math.random();
    },
    addshowpingcar: function () {
        var openid = $.cookie("openid");
        if (isUndefinedNullOrEmpty(openid)) {
            alert("下单失败请稍候再购买");
            return false;
        }
        var str = document.getElementsByName("allname");
        var objarray = str.length;
        var chestr = "";
        for (i = 0; i < objarray; i++) {
            if (str[i].checked == true) {
                if (chestr == "") {
                    chestr += str[i].value.replace("radio", "");
                }
                else {
                    chestr += "|" + str[i].value.replace("radio", "");
                }
            }
        }
        if (chestr == "") {
            alert("请选择商品");
            return;
        }
        var data = openid + "|" + chestr;
        poststr = "{\"type\":\"addshowpinghcar\",\"htmldata\":\"" + data + "\"}";
        this.postajaxs(poststr, this.saveresult);
    },
    saveresult: function (data) {
        alert(data.msg);
    },
    postajaxs: function (postdata, fangfa) {
        mj_ajax("../Handler1.ashx", "json", postdata, fangfa)
    }
}